package com.falcon.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.bean.BeanUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swan.mybatis.condition.Condition;
import com.falcon.mvc.domain.BasePager;
import com.falcon.core.utils.BeanUtils;

import com.falcon.domain.po.EditColumnPO;
import com.falcon.domain.dos.EditColumnDO;
import com.falcon.domain.req.EditColumnQuery;
import com.falcon.domain.req.EditColumnRequest;

import com.falcon.mapper.IEditColumnMapper;
import com.falcon.service.IEditColumnService;


@Slf4j
@Service
public class EditColumnService implements IEditColumnService {

    @Autowired
    private IEditColumnMapper editColumnMapper;

    @Override
    public Long save(EditColumnRequest request){
        EditColumnPO editColumnPO = BeanUtil.copyProperties(request, EditColumnPO.class);

        this.editColumnMapper.insertNotNull(editColumnPO);

        return editColumnPO.getId();
    }

    @Override
    public Boolean update(Long id, EditColumnRequest request){

        EditColumnPO editColumnPO = BeanUtil.copyProperties(request, EditColumnPO.class);
        editColumnPO.setId(id);

        return this.editColumnMapper.updateNotNull(editColumnPO);
    }

    @Override
    public Boolean deleteById(Long id) {

        return this.editColumnMapper.deleteById(id);
    }

    @Override
    public EditColumnDO queryById(Long id){

        EditColumnPO editColumnPO = this.editColumnMapper.selectById(id);

        EditColumnDO editColumnDO = BeanUtil.copyProperties(editColumnPO, EditColumnDO.class);

        return editColumnDO;
    }


    @Override
    public List<EditColumnDO> queryList(EditColumnQuery request){

        Condition condition = request.toCondition();

        List<EditColumnPO> poList = this.editColumnMapper.selectList(condition);

        List<EditColumnDO> doList = BeanUtil.copyToList(poList, EditColumnDO.class);

        return doList;
    }

    @Override
    public BasePager<EditColumnDO> queryPager(EditColumnQuery request){


        PageInfo<EditColumnPO> pageInfo = PageHelper.startPage(request.getPage(), request.getPageSize())
                .doSelectPageInfo(() -> this.editColumnMapper.selectList(request.toCondition()));

        return BeanUtils.toPager(pageInfo, EditColumnDO.class);
    }

    @Override
    public int batchDelete(List<Long> ids) {

        return this.editColumnMapper.deleteByIds(ids);
    }


}
